package com.hsyt.pms.sys.dubbo.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.hsyt.pfc.support.rpc.PageResult;
import com.hsyt.pms.api.dto.system.SysPersonDto;
import com.hsyt.pms.api.vo.system.SysPersonVo;
import com.hsyt.pms.orm.sys.SysPersonDao;
import com.hsyt.pms.sys.dubbo.SysPersonService;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName: SysPersonServiceImpl
 * @Description: 人员管理业务层实现
 * @author wangze@hsyuntai.com
 * @date 2019年2月12日 下午2:45:51
 */
@Slf4j
@Component
@Service(version = "0.0.1", interfaceClass = SysPersonService.class, registry = "pms", group = "pmsSystem", timeout = 3000)
public class SysPersonServiceImpl implements SysPersonService {

    private static final Logger LOGGER = LoggerFactory.getLogger(SysPersonServiceImpl.class);

    @Resource
    private SysPersonDao pmsPersonDao;

    @Override
    public PageResult<SysPersonVo> searchPageDataByDto(SysPersonDto dto) {
        Page<?> page = PageHelper.startPage(dto.getPageNumber(), dto.getPageSize(), true);
        List<SysPersonDto> list = pmsPersonDao.findPaginationDataByCondition(dto);
        PageResult result = new PageResult();
        result.setResult(true);
        result.setMessage("分页查询成功");
        result.setTotal(page.getTotal());
        result.setRows(list);
        return result;
    }

    @Override
    public int insertPerson(SysPersonDto dto) {
        return pmsPersonDao.insertSelective(dto);
    }

    @Override
    public int updatePerson(SysPersonDto dto) {
        return pmsPersonDao.updateByPrimaryKeySelective(dto);
    }

}
